home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
-
-
- #include "system_headers.h"
-
- APTR BT_SemUpdate,BT_SemPrint,BT_SemObtain,BT_SemRelease,BT_SemRemove,BT_SemExit;
- APTR semtext,semlist;
-
- APTR semcount;
- int semcnt;
-
- static APTR SemPool;
-
- __asm __saveds LONG semlist_dspfunc(register __a2 char **array, register __a1 struct SemEntry *sementry, register __a0 struct Hook *hook)
- {
- if (sementry) {
- *array++ = sementry->sm_address;
- *array++ = sementry->sm_name;
- *array++ = sementry->sm_nestcount;
- *array++ = sementry->sm_queuecount;
- *array++ = sementry->sm_owner;
- *array = NULL;
- } else {
- *array++ = ESC "bAddress";
- *array++ = ESC "bName";
- *array++ = ESC "bNest";
- *array++ = ESC "bQueue";
- *array++ = ESC "bOwner";
- *array = NULL;
- }
- return(0);
- }
-
- struct Hook semlist_dsphook = {
- {NULL, NULL},
- (ULONG (* )())semlist_dspfunc,
- NULL, NULL
- };
-
- __asm __saveds LONG semlist_cmpfunc(register __a1 struct SemEntry *sementry1, register __a2 struct SemEntry *sementry2)
- {
- return strcmpi(sementry1->sm_name, sementry2->sm_name);
- }
-
- struct Hook semlist_cmphook = {
- {NULL, NULL},
- (ULONG (* )())semlist_cmpfunc,
- NULL, NULL
- };
-
- void FreeSemaphores (void)
- {
- MyFreePoolStructs(&SemPool, semtext, NULL, semlist);
- }
-
- int GetSemaphores (struct SemEntry **first) {
- struct SignalSemaphore *sem;
- struct SemEntry *sementry,*previous = NULL;
-
- int semcnt = 0;
- *first = 0;
-
- if (!SemPool) SemPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
-
- if (clientstate) {
- if (SendDaemon ("GetSemList")) {
- while ((sementry = tbAllocPooled(SemPool, sizeof(struct SemEntry))) \
- && (ReceiveDecodedEntry ((UBYTE *) sementry, sizeof (struct SemEntry)))) {
- IsHex (sementry->sm_address, (long *) &sementry->sm_adr);
-
- if (! *first)
- *first = sementry;
- if (previous)
- previous->sm_next = sementry;
-
- semcnt++;
- previous = sementry;
- }
- }
- } else {
- sem = FIRSTSEMAPHORE;
-
- while ((sem->ss_Link.ln_Succ != 0) && (sementry = tbAllocPooled(SemPool, sizeof(struct SemEntry)))) {
- if (! *first)
- *first = sementry;
- if (previous)
- previous->sm_next = sementry;
-
- sementry->sm_adr = sem;
-
- _sprintf (sementry->sm_address, "$%08lx", sem);
- strncpy (sementry->sm_name, nonetest (sem->ss_Link.ln_Name), FILENAMELENGTH);
- _sprintf (sementry->sm_nestcount, "%3ld ", sem->ss_NestCount);
- if (sem->ss_Owner) {
- _sprintf (sementry->sm_queuecount, "%3ld ", sem->ss_QueueCount);
- strncpy (sementry->sm_owner, nonetest (GetTaskName (sem->ss_Owner)), NODENAMELENGTH);
- } else {
- strcpy (sementry->sm_queuecount, "--- ");
- strcpy (sementry->sm_owner, "-----");
- }
-
- semcnt++;
- previous = sementry;
- sem = (struct SignalSemaphore *) sem->ss_Link.ln_Succ;
- }
- }
- return (semcnt);
- }
-
- void PrintSemaphores (char *filename) {
- int i=1;
- BPTR handle;
- struct SemEntry *entryp = NULL;
-
- handle = HandlePrintStart (filename);
- if ((handle) && (PrintOneLine (handle, "\n Address Name Nest Queue Owner\n\n"))) {
- if (! WI_Semaphores) {
- i = GetSemaphores (&entryp);
- }
- if (i) {
- for (i=0;;i++) {
- if (WI_Semaphores)
- DoMethod (semlist,MUIM_List_GetEntry,i,&entryp);
- if (!entryp) break;
-
- if (strcmp (entryp->sm_owner, "<none>"))
- _sprintf (tmpstr2, " %s %-30s %4s %5s %s\n", entryp->sm_address, entryp->sm_name, entryp->sm_nestcount, entryp->sm_queuecount, entryp->sm_owner);
- else
- _sprintf (tmpstr2, " %s %-30s %4s --- -----\n", entryp->sm_address, entryp->sm_name, entryp->sm_nestcount);
-
- if (! (PrintOneLine (handle, tmpstr2)))
- break;
-
- if (! WI_Semaphores)
- entryp = entryp->sm_next;
- }
- }
- }
- HandlePrintStop();
- }
-
- void ShowSemaphores (void) {
- struct SemEntry *sem;
-
- ApplicationSleep();
- set (semlist,MUIA_List_Quiet,TRUE);
- set (BT_SemObtain, MUIA_Disabled, TRUE);
- set (BT_SemRelease, MUIA_Disabled, TRUE);
- set (BT_SemRemove, MUIA_Disabled, TRUE);
-
- FreeSemaphores();
- semcnt = GetSemaphores (&sem);
-
- while (sem) {
- InsertSortedEntry (semlist, (APTR *) &sem);
- sem = sem->sm_next;
- }
-
- SetCountText (semcount, semcnt);
- AwakeApplication();
- set (semlist,MUIA_List_Quiet,FALSE);
- }
-
- void SendSemList (void) {
- struct SemEntry *sem;
-
- FreeSemaphores();
- GetSemaphores (&sem);
-
- while (sem) {
- SendEncodedEntry ((UBYTE *) sem, sizeof (struct SemEntry));
- sem = sem->sm_next;
- }
- FreeSemaphores();
- }
-
-
- char semaphores_title[WINDOWTITLELEN];
-
- void SemaphoresWindow (BOOL state) {
- if (state) {
- if (WI_Semaphores) {
- ShowSemaphores();
- } else {
- WI_Semaphores = WindowObject,
- MUIA_Window_Title, MyGetWindowTitle (semaphores_title, "SEMAPHORES"),
- MUIA_HelpNode, SemaphoresText,
- MUIA_Window_ID, MakeListID('S','E','M','A'),
- WindowContents, VGroup,
- Child, semlist = MySortedListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8",&semlist_dsphook, &semlist_cmphook),
- Child, MyBelowListview (&semtext, &semcount),
- Child, MyVSpace(2),
- Child, HGroup, MUIA_Group_SameSize, TRUE,
- Child, BT_SemUpdate = KeyButtonA (UpdateText ,ID_SEMUPDATE),
- Child, BT_SemPrint = KeyButtonA (PrintText ,ID_SEMPRINT),
- Child, BT_SemObtain = KeyButtonA (ObtainText ,ID_SEMOBTAIN),
- Child, BT_SemRelease = KeyButtonA (ReleaseText,ID_SEMRELEASE),
- Child, BT_SemRemove = KeyButtonA (RemoveText ,ID_SEMREMOVE),
- Child, BT_SemExit = KeyButtonA (ExitText ,ID_SEMEXIT),
- End,
- End, End;
-
- DoMethod (AP_Scout,OM_ADDMEMBER,WI_Semaphores);
- DoMethod (WI_Semaphores,MUIM_Window_SetCycleChain,semlist,BT_SemUpdate,BT_SemPrint,BT_SemObtain,BT_SemRelease,BT_SemRemove,BT_SemExit,NULL);
-
- SetCloseRequest (WI_Semaphores,ID_SEMEXIT);
- SetListActive (semlist,ID_SEMLV_ACTIVE);
-
- ShowSemaphores();
-
- SetWindowOpen (WI_Semaphores,semlist,ID_SEMEXIT);
- }
- } else if ((! state) && (WI_Semaphores)) {
- SetWindowClose (WI_Semaphores,TRUE);
-
- FreeSemaphores();
-
- DoMethod (AP_Scout,OM_REMMEMBER,WI_Semaphores);
- MUI_DisposeObject (WI_Semaphores);
- WI_Semaphores = NULL;
- semlist = NULL;
- }
- }
-
-